package com.e3.sysmg.security.client;

import java.util.ArrayList;
import java.util.List;

import com.e3.sysmg.security.model.ModuleModel;
import com.e3.sysmg.security.model.ModuleQC;
import com.e3.template.tgf.TGFQueryDialog;
import com.e3.web.core.client.GwtAsyncCallback;
import com.e3.web.core.model.SuperQC;
import com.e3.web.widget.client.MyField;
import com.extjs.gxt.ui.client.widget.form.Field;
/**
 * 
 * @author JANTY
 *
 */
public class ModuleQueryDialog extends TGFQueryDialog<ModuleModel> {
	
	private ModuleRPCServiceAsync service = ModuleRPCService.Util.getInstance();
	
	@Override
	protected SuperQC getQueryCondition() {
		MyField<?> field = getMyFormField(ModuleModel.CODE);
		String code = (String)field.getFieldValue();
		field = getMyFormField(ModuleModel.NAME);
		String name = (String)field.getFieldValue();
		field = getMyFormField(ModuleModel.STATUS);
		String status = (String)field.getFieldValue();
		
		final ModuleQC qc = new ModuleQC();
		qc.setCode(code);
		qc.setName(name);
		qc.setStatus(status);
		return qc;
	}

	@Override
	protected List<Field<?>> getFormFields() {
		String[] names = {ModuleModel.CODE,ModuleModel.NAME,ModuleModel.STATUS};
		List<Field<?>> fields = new ArrayList<Field<?>>();
		
		for (String name : names) {
			Field<?> formField = ModuleHelper.INSTANCE.createFormField(name);
			fields.add(formField);
		}
	
		return fields;
	}

	@Override
	protected void executeQueryService(SuperQC qc,GwtAsyncCallback<List<ModuleModel>> callback) {
		service.getModulesByCondition((ModuleQC)qc, callback);
	}
	
}
